package bank

import (
	"context"
	"group-buy/group_buy/internal/models"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BankLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBankLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BankLogic {
	return &BankLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BankLogic) Bank(req *types.ListBankReq) (resp *types.ListBankRsp, err error) {
	data := make([]*models.BranchData, 0)
	err = l.svcCtx.Engine.Where("bank_code=?", req.BankCode).Cols("branch_code", "branch_name").Find(&data)
	if err != nil {
		return nil, err
	}
	list := make([]*types.BranchData, len(data), len(data))
	for i, _ := range data {
		list[i] = &types.BranchData{
			BranchCode: data[i].BranchCode,
			BranchName: data[i].BranchName,
			//BankCode:   data[i].BankCode,
			//BankName:   data[i].BankName,
		}
	}

	return &types.ListBankRsp{
		List: list,
	}, nil
}
